package task.manager;

import java.util.ArrayList;
import java.util.List;

/**
 * Sorts tasks by completion.
 * 
 * @author Harrison Saylor, Aaron Mead, Marc Huet, Greg Ruskin
 * @version 2
 */
public class TaskSorterCompletion implements TaskSorter {

	UserDataFacade userDataFacade;
	String activeCategory;
	
	
	public TaskSorterCompletion() {
		userDataFacade = UserDataFacade.getInstance();
		
	} // End of constructor.
	
	@Override
	public String[] getSortedTaskArray(String category) {
		TaskList taskList = userDataFacade.getTaskList();
		activeCategory = category;
		List<String> tempArray = new ArrayList<String>();
		
		if(activeCategory.equals("All")){
			for(int i = 0;i<taskList.size();i++){
				if(taskList.get(i).isComplete()){
					tempArray.add(taskList.get(i).getTitle());
				}
			}
		}
		else{
			for(int i = 0;i<taskList.size();i++){
				if(taskList.catNameEquals(i,activeCategory)){
					if(taskList.get(i).isComplete()){
						tempArray.add(taskList.get(i).getTitle());
						System.out.println(taskList.get(i).getTitle());
					}
				}
			}
			tempArray.add("Add New Task");
		}
		
		
		
		String[] retArray = new String[tempArray.size()];
		tempArray.toArray(retArray);
		
		return retArray;
	}

}
